package com.srv.servlet;

import java.io.IOException;
import java.util.ArrayList;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.srv.TheException;
import com.srv.model.ID;
import com.srv.model.User;
import com.srv.service.IDService;


public class ServletNodeGetid extends HttpServlet {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1121212112221L;
	private static Log log = LogFactory.getLog(ServletNodeGetid.class);
    private final static String STR_C="c";
	public void doGet(HttpServletRequest request, HttpServletResponse response)
	throws ServletException, IOException {
try{
	response.setContentType(ConstText.TextHtml);
	ResponseResult result = new ResponseResult();
	User theUser = RequestTool.getAccessUser(request);			
	//未登陆
	if(theUser==null){				
		result.theResult = ResponseResult.RESULT_FAIL;//结果失败
		result.theMessageObj = ConstText.NotLogin;
		ResponseTool.repsone(request,response,result);
		return;
	}
	
	String c = request.getParameter(STR_C);	
	int counter = 0;
	//检查是否合法的值：整数
	try{
		if(c==null){throw new java.lang.NumberFormatException();}
		counter=Integer.parseInt(c);
		if(counter>100||counter<=0){throw new java.lang.NumberFormatException();}
	}catch(java.lang.NumberFormatException ne){
		result.theResult = ResponseResult.RESULT_FAIL;//结果失败
		result.theMessageObj = ConstText.PARAMETER_IS_INVALID;
		ResponseTool.repsone(request,response,result);
		return;
	}
	 //参数检查，id为travel的id
	 String tid = RequestTool.getValueOfID(request);				
	 //检查ID是否合法
	 ID idObj = IDService.getID(tid);
	 if(idObj==null){	 
		 result.theResult = ResponseResult.RESULT_FAIL;//结果失败
		 result.theMessageObj=ConstText.ID_IS_INVALID;
		 ResponseTool.repsone(request,response,result);
		 return;		 
	 }
	 ArrayList<String> extend = new ArrayList<String>();
	 extend.add(tid);
	result.theMessageObj = IDService.createIDArray(theUser,counter,ID.ID_TYPE_4_NODE,extend);								
	ResponseTool.repsone(request,response,result);
		
}catch(TheException te){
	log.error(te.getMessage());
}
}	

}
